package com.pronosticnews.client.admin.navigation;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.Window;
import com.pronosticnews.client.admin.ClientFactory;
import com.pronosticnews.client.admin.activity.AccueilActivity;
import com.pronosticnews.client.admin.activity.ActivityCallbackHandler;
import com.pronosticnews.client.admin.activity.EditPaysActivity;
import com.pronosticnews.client.admin.activity.ListChampionnatActivity;
import com.pronosticnews.client.admin.activity.ListClubActivity;
import com.pronosticnews.client.admin.activity.ListJoueurActivity;
import com.pronosticnews.client.admin.activity.ListJourneesActivity;
import com.pronosticnews.client.admin.activity.ListPaysActivity;
import com.pronosticnews.client.admin.activity.ListSaisonActivity;
import com.pronosticnews.client.admin.activity.ListSportActivity;
import com.pronosticnews.client.admin.activity.ListStadeActivity;
import com.pronosticnews.client.admin.navigation.sync.AsyncActivityMapper;
import com.pronosticnews.client.admin.place.AccueilPlace;
import com.pronosticnews.client.admin.place.ChampionnatPlace;
import com.pronosticnews.client.admin.place.ClubPlace;
import com.pronosticnews.client.admin.place.JoueurPlace;
import com.pronosticnews.client.admin.place.JourneePlace;
import com.pronosticnews.client.admin.place.PaysPlace;
import com.pronosticnews.client.admin.place.SaisonPlace;
import com.pronosticnews.client.admin.place.SportPlace;
import com.pronosticnews.client.admin.place.StadePlace;

public class ListActivityMapper implements AsyncActivityMapper {

	ClientFactory clientFactory = null;

	public ListActivityMapper(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}

	@Override
	public void getActivity(final Place place, final
			ActivityCallbackHandler activityCallbackHandler) {
		if (place instanceof ChampionnatPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListChampionnatActivity(clientFactory));
				}
			});
		}
		else if (place instanceof PaysPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListPaysActivity(clientFactory));
				}
			});
		}
		else if (place instanceof SportPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListSportActivity(clientFactory));
				}
			});
		}
		else if (place instanceof AccueilPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new AccueilActivity());
				}
			});
		}
		else if (place instanceof ClubPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListClubActivity(clientFactory));
				}
			});
		}
		else if (place instanceof JoueurPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListJoueurActivity(clientFactory));
				}
			});
		}
		else if (place instanceof StadePlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListStadeActivity(clientFactory));
				}
			});
		}
		else if (place instanceof SaisonPlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListSaisonActivity((SaisonPlace)place,clientFactory));
				}
			});
		}
		else if (place instanceof JourneePlace) {
			GWT.runAsync(new RunAsyncCallback() {

				public void onFailure(Throwable err) {
	
					Window.alert("Fail to load activity");
				}

				public void onSuccess() {
					activityCallbackHandler
							.onRecieveActivity(new ListJourneesActivity((JourneePlace)place,clientFactory));
				}
			});
		}
		else {
			activityCallbackHandler.onRecieveActivity(null);
		}
		
	}

}
